//
//  PressHouseStyleViewController.m
//  Fangmm
//
//  Created by ChaoZhou on 16/3/14.
//  Copyright © 2016年 com.fangmm. All rights reserved.
//

#import "PressHouseStyleViewController.h"
#import "RoomNumTableViewCell.h"
#import "HallNumTableViewCell.h"
#import "TolietNumTableViewCell.h"
#import <MobClick.h>
@interface PressHouseStyleViewController ()<UITableViewDataSource,UITableViewDelegate,roomNumButtonClickDelegate,HallNumTableViewCellDelegate,TolietNumTableViewCellDelegate>
{
    RoomNumTableViewCell *roomNumCell;
    HallNumTableViewCell *hallNumCell;
    TolietNumTableViewCell *tolietNumCell;
    
    House            *pressHouse;
    int               roomNum;
    int               hallNum;
    int               tolietNum;
}

@end

@implementation PressHouseStyleViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"发布房源设置室，厅，卫，页面"];}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"发布房源设置室，厅，卫，页面"];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    roomNum = 1;
    hallNum = 1;
    tolietNum = 1;
    pressHouse = [[House alloc]init];
    self.mainTableView.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"screen_bg"]];
    [_mainTableView registerNib:[UINib nibWithNibName:@"RoomNumTableViewCell" bundle:nil] forCellReuseIdentifier:@"RoomNumTableViewCell"];
    [_mainTableView registerNib:[UINib nibWithNibName:@"HallNumTableViewCell" bundle:nil] forCellReuseIdentifier:@"HallNumTableViewCell"];
    [_mainTableView registerNib:[UINib nibWithNibName:@"TolietNumTableViewCell" bundle:nil] forCellReuseIdentifier:@"TolietNumTableViewCell"];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row)
    {
        case 0:
        {
            return 205;
        }
            break;
        case 1:
        {
            return 160;
        }
            break;
        default:
        {
            return 160;
        }
            break;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row)
    {
        case 0:
        {
            roomNumCell = [tableView dequeueReusableCellWithIdentifier:@"RoomNumTableViewCell"];
            [roomNumCell rectRoomNumButtonView];
            roomNumCell.delegate =self;
            return roomNumCell;
        }
            break;
        case 1:
        {
            hallNumCell = [tableView dequeueReusableCellWithIdentifier:@"HallNumTableViewCell"];
            [hallNumCell rectHallNumButtonView];
            hallNumCell.delegate = self;
            return hallNumCell;
        }
            break;
        default:
        {
            tolietNumCell = [tableView dequeueReusableCellWithIdentifier:@"TolietNumTableViewCell"];
            [tolietNumCell rectTolietNumCell];
            tolietNumCell.delegate = self;
            return tolietNumCell;
        }
            break;
    }
    return nil;
}

-(void)whenClickRoomNumButton:(UIButton *)sender
{
    roomNumCell.selectIndex = (int)sender.tag;
    roomNum = (int)sender.tag + 1;
    [_mainTableView reloadData];
}
-(void)whenClickHallNumButton:(UIButton *)sender
{
    hallNumCell.selectIndex = (int)sender.tag;
    hallNum = (int)sender.tag + 1;
    [_mainTableView reloadData];
}
-(void)whenClickTolietNumButton:(UIButton *)sender
{
    tolietNumCell.selectIndex = (int)sender.tag;
    tolietNum = (int)sender.tag + 1;
    [_mainTableView reloadData];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)backClick:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)completePress:(id)sender
{
    pressHouse.roomNum      = roomNum;
    pressHouse.hallNum      = hallNum;
    pressHouse.toiletNum    = tolietNum;
    self.houseStyle = [NSString stringWithFormat:@"%d室%d厅%d卫",roomNum,hallNum,tolietNum];
    [self.delegate ConfigTheHouseStyleWith:pressHouse];
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
